package com.example.proxy;

import com.example.dto.RefreshBean;
import com.example.service.SysBeanService;
import net.sf.cglib.proxy.Enhancer;
import org.springframework.context.ApplicationContext;

public class DefaultProxyBeanHelper {

    /****
     * 创建一个代理对象
     * @param refreshBean
     * @return
     */
    public static Object createProxy(RefreshBean refreshBean, ApplicationContext applicationContext) {
        SysBeanService sysBeanService = applicationContext.getBean(SysBeanService.class);
        DefaultProxyBean defaultProxyBean = new DefaultProxyBean(refreshBean, applicationContext);
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(refreshBean.getBeanClass());
        enhancer.setCallback(defaultProxyBean);
        sysBeanService.getRefreshProxyBeans().add(defaultProxyBean);
        return enhancer.create();
    }
}
